package cn.biao.epic.sys.modular.system.service.impl;

import cn.biao.epic.core.util.ToolUtil;
import cn.biao.epic.sys.modular.system.entity.Position;
import cn.biao.epic.sys.modular.system.mapper.PositionMapper;
import cn.biao.epic.sys.modular.system.model.params.PositionParam;
import cn.biao.epic.sys.modular.system.model.result.PositionResult;
import cn.biao.epic.sys.modular.system.service.PositionService;
import cn.biao.epic.sys.modular.system.service.UserPosService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.List;

/**
 * @Auther Uncle_Z
 * @date 2019/12/9 18:48
 * @Email:2545375@qq.com
 * @Descrition
 */
@Service
public class PositionServiceImpl extends ServiceImpl<PositionMapper, Position> implements PositionService {

    @Autowired
    private UserPosService userPosService;

    @Override
    public void add(PositionParam param) {
        Position entity = getEntity(param);
        this.save(entity);
    }

    @Override
    public void delete(PositionParam param) {
        this.removeById(getKey(param));
    }

    @Override
    public void update(PositionParam param) {
        Position oldEntity = getOldEntity(param);
        Position newEntity = getEntity(param);
        ToolUtil.copyProperties(newEntity, oldEntity);
        this.updateById(newEntity);
    }

    @Override
    public PositionResult findBySpec(PositionParam param) {
        return null;
    }

    @Override
    public List<PositionResult> findListBySpec(PositionParam param) {
        return null;
    }


    private Serializable getKey(PositionParam param) {
        return param.getPositionId();
    }

    private Page getPageContext() {
        return new Page<Position>(1,20);
    }

    private Position getOldEntity(PositionParam param) {
        return this.getById(getKey(param));
    }

    private Position getEntity(PositionParam param) {
        Position entity = new Position();
        ToolUtil.copyProperties(param, entity);
        return entity;
    }
}
